{extend name="public/base" /}

{block name="title"}<title>{$Think.lang.list}</title>{/block}

{block name="pjax_container"}
<div class="hry-content-wrapper">
<section class="content-header">
    <ol class="breadcrumb">
        <li>企业端管理</li>
        <li class="active">项目代付</li>
    </ol>
</section>
<section class="content">
    <div class="row">
        <div class="col-md-12">
            <div class="hry-form-wrapper">
                <div class="box-header with-border" style="padding:15px;">
                    <h3 class="box-title"></h3>
                    {include file="public/project_side_project_daifu_search" /}
                </div>
                <div style="margin-top: 10px;text-align: right;margin-right: 10px">
                    {if condition="!empty($money) || $money != 0"}
                    <span style="color: orange;display: inline-block;margin-right: 50px">以下订单认投金额总和为{:number_format($total_money,2)}元</span>
                    {if condition="$is_show eq 1"}
                    <button type="button" class="btn btn-primary" id="connect">关联项目</button>
                    {else}
                    <button type="button" class="btn btn-primary batch-daifu" data-id="{$afm_id}">一键批量代付</button>
                    {/if}
                    {/if}

                </div>
                <div class="box-body table-responsive">
                    <table class="table table-bordered table-hover table-sort">
                        <tr>
                            <th>订单ID{if condition="empty($money) || $money eq 0"}{:table_sort('id')}{/if}</th>
                            <th>订单号</th>
                            <th>姓名</th>
                            <th>手机号</th>
							<th>认投金额</th>
							<th>所属项目</th>
                            <th>项目方</th>
                            <th>状态</th>
                            <th width="178">申请期数</th>
                            <th width="100">操作</th>
                        </tr>
                        {volist name="dataList" id="vo"}
                        <tr>
                            <td>{$vo.id}</td>
                            <td>{$vo.order_sn}</td>
                            <td>{$vo.username}</td>
                            <td>{$vo.mobile}</td>
							<td>{$vo.money}</td>
                            <td>{$vo.project_name}</td>
                            <td>{$vo.company_name}</td>
                            {if condition="$vo.payment_status eq 0"}
                            <td><span class="status status-warning">未代付</span></td>
                            {/if}
                            {if condition=" $vo.payment_status eq 1"}
                            <td><span class="status status-success">已代付</span></td>
                            {/if}
                            {if condition="$vo.payment_status eq 2"}
                            <td><span class="status status-error">代付失败</span></td>
                            {/if}
                            <td> {if condition="$vo.series_number !=''"}{$vo.series_number}{else}--{/if}</td>
                            <td>
                                {if condition="$vo.relevance_id >0 && $vo.series_number>0 && $vo.payment_status!=1 "}
                                <a class="btn-text btn-primary daifu" data-id="{$vo.id}">代付</a>
                                {else}
                                --
                                {/if}
                            </td>
                        </tr>
                        {/volist}
                    </table>
                </div>
            </div>
            <div class="box-footer clearfix">
                {$dataList->render()}
            </div>
        </div>
    </div>
</section>
</div>
<script type="text/javascript">
$(function(){
    $('#connect').on('click', function () {
        let data = {
            project_id: getQueryVariable('project_id'),
            money:getQueryVariable('money')
        }
        $.ajax({
            url: '/hryweb.php/project_side/sureRelated',
            data: data,
            type: "POST",
            dataType: "json",
            success: function (result) {
                if (result.status == 1) {
                    $.amaran({'message': result.info});
                    window.location.href = result.url;
                } else {
                    $.amaran({'message': result.info});
                }
            },
            error: function (result, xhr, status, errorThrown) {
                $.amaran({'message': result.info})
            },
            complete: function (xhr, status) {
//                    alert('The request is complated');
            },
            beforesend: function () {
            },
            cache: false,//true
            async: true
        })
    })
    $('.daifu').on('click', function () {
        let id = $(this).attr('data-id')
        let obj = {
            order_id: id
        }
        $.ajax({
            url: '/hryweb.php/project_side/signalOrderPay',
            data: obj,
            type: "POST",
            dataType: "json",
            success: function (result) {
                if (result.status == 1) {
                    $.amaran({'message': result.info});
                    window.location.reload();
                } else {
                    $.amaran({'message': result.info});
                }
            },
            error: function (result, xhr, status, errorThrown) {
                $.amaran({'message': result.info})
            },
            complete: function (xhr, status) {
//                    alert('The request is complated');
            },
            beforesend: function () {
            },
            cache: false,//true
            async: true
        })
    })
    $('.batch-daifu').on('click', function () {
        let id = $(this).attr('data-id')
        let obj = {
            afm_id: id
        }
        $.ajax({
            url: '/hryweb.php/project_side/batchOrderPay',
            data: obj,
            type: "POST",
            dataType: "json",
            success: function (result) {
                if (result.status == 1) {
                    $.amaran({'message': result.info});
                    window.location.reload();
                } else {
                    $.amaran({'message': result.info});
                }
            },
            error: function (result, xhr, status, errorThrown) {
                $.amaran({'message': result.info})
            },
            complete: function (xhr, status) {
//                    alert('The request is complated');
            },
            beforesend: function () {
            },
            cache: false,//true
            async: true
        })
    })
    {if condition=" $rest_login == 1 "}
    restlogin('{$rest_login_info}');   //登录超时
    {/if}
})
function getQueryVariable(variable)
{
    var query = window.location.search.substring(1);
    var vars = query.split("&");
    for (var i=0;i<vars.length;i++) {
        var pair = vars[i].split("=");
        if(pair[0] == variable){return pair[1];}
    }
    return(false);
}
</script>
<style>
    .status{
        display: inline-block;
        padding: 3px 15px;
        color: white;
        border-radius: 15px;
        font-size: 12px;
    }
    .status-error{
        background: #f5222d;
    }
    .status-success{
        background: #52c41a;
    }
    .status-warning{
        background: #faad14;
    }
</style>
{/block}